# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=gtk+3.0
pkgver=3.24.38
pkgrel=7
pkgdesc="The GTK+ Toolkit (v3)"
url="https://www.gtk.org/"
install="$pkgname.post-deinstall"
triggers="$pkgname.trigger=/usr/lib/gtk-3.0/immodules:/usr/lib/gtk-3.0/*/immodules gtk-update-icon-cache.trigger=/usr/share/icons/*"
arch="all"
license="LGPL-2.1-or-later"
options="!check" # checkdepends in community
subpackages="
	$pkgname-dbg
	$pkgname-demo
	$pkgname-dev
	$pkgname-doc
	$pkgname-lang
	gtk-update-icon-cache:icon_cache
	"
depends="shared-mime-info gtk-update-icon-cache"
depends_dev="
	at-spi2-core-dev
	gdk-pixbuf-dev
	glib-dev
	libepoxy-dev
	libxext-dev
	libxi-dev
	libxinerama-dev
	libxkbcommon-dev
	wayland-libs-client
	wayland-libs-cursor
	wayland-protocols
	"
_icon_cache_depends="hicolor-icon-theme"
makedepends="
	$depends_dev
	$_icon_cache_depends
	cairo-dev
	cups-dev
	expat-dev
	fontconfig-dev
	gettext-dev
	gobject-introspection-dev
	hicolor-icon-theme
	iso-codes-dev
	libice-dev
	libx11-dev
	libxcomposite-dev
	libxcursor-dev
	libxdamage-dev
	libxfixes-dev
	libxrandr-dev
	meson
	pango-dev
	tiff-dev
	wayland-dev
	zlib-dev
	"
checkdepends="
	ibus
	xvfb-run
	"
source="https://download.gnome.org/sources/gtk+/${pkgver%.*}/gtk+-$pkgver.tar.xz
	charcode.patch
	dbus-crash.patch
	glsync-fix.patch
	offscreen-crash.patch
	pad-fix.patch
	password-segv.patch
	stylus-map.patch
	x11-perf.patch
	"
builddir="$srcdir/gtk+-$pkgver"

build() {
	CFLAGS="$CFLAGS -O2" \
	CXXFLAGS="$CXXFLAGS -O2" \
	abuild-meson \
		-Db_lto=true \
		-Dman=true \
		-Dgtk_doc=false \
		-Dbroadway_backend=true \
		-Dtests="$(want_check && echo true || echo false)" \
		output
	meson compile -C output
}

check() {
	xvfb-run -a meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

dev() {
	default_dev

	amove usr/bin/gtk-builder-tool \
		usr/bin/gtk-encode-symbolic-svg \
		usr/bin/gtk-query-settings
}

doc() {
	default_doc
	# gtk-update-icon-cache
	replaces="gtk+2.0-doc"
}

demo() {
	pkgdesc="$pkgdesc (demonstration application)"
	amove usr/bin/gtk3-demo \
		usr/bin/gtk3-demo-application \
		usr/bin/gtk3-icon-browser \
		usr/bin/gtk3-widget-factory \
		usr/share/gtk-3.0/gtkbuilder.rng \
		usr/share/glib-2.0/schemas/org.gtk.Demo.gschema.xml \
		usr/share/applications/gtk3-demo.desktop \
		usr/share/applications/gtk3-icon-browser.desktop \
		usr/share/applications/gtk3-widget-factory.desktop \
		usr/share/icons
}

lang() {
	default_lang

	amove usr/share/gtk-3.0/emoji
}

icon_cache() {
	depends="$_icon_cache_depends"
	replaces="gtk4.0" # gtk4-update-icon-cache

	# provide gtk4 symlink too
	amove usr/bin/gtk-update-icon-cache
	ln -s gtk-update-icon-cache "$subpkgdir"/usr/bin/gtk4-update-icon-cache
}

sha512sums="
e99ec10959191b55013fce37e83f0e85bf36597db101e324081479792a2047d032cf0d213d69c02eeb4b7cd6d56d6489b7b2a60904b2bd7af23ea1b9c5a79528  gtk+-3.24.38.tar.xz
95a000d04c35915e36cc4c2c917136a405bbeacde04b59dc456a1820e0052e56cfd50d1eb013dfda2a8c8d94be9de6ce1f8c522d9cb57324172c9653c6543d4d  charcode.patch
563c607c956b5b055269c39d27af23c9c51b99cad8a8f643ce31b522008f01070edb3247f06c84e836fd29eec2453650ad936c997226c4b956e649ec688375d5  dbus-crash.patch
7da0aac2d369fd3aaca8e8c247cdc322e592acbbff3aaad33c678cdcdb91b9d9e7791f87af0a0fb22cca23c86ff8fffa1378ab695162e2bbd486ba94751738ee  glsync-fix.patch
ea49cea1cf12b8a1c0c9648d6c1d06a437b667fa0ca515085f25d0c600f8cb381f14b912365dc529b2bdbd30fcc067bc5b14760e9a9974286cc9caf223e4777a  offscreen-crash.patch
75ac81233a98d0001ea7be54758fa468d6ea452d799f9250745a1127a0663a26129cfeada89a4c54c79b7db702f98c795deedb85679042d76ecf46c10dae1d20  pad-fix.patch
4d80049d637fd64d6b99ecfb0ab40e883e43729f183a05b528ee692c69016d28cae2772ee8defb88fe2a209d1bf71e036d04a8ebffb81a89934d3d48abda7510  password-segv.patch
006d63ba658861dde207ec6996ee07a1bf51f39b667e78878bbe9bf407606fc31cd78ac5f25108040967e04d88a2889d37e153755b918fa302e3b523528edaef  stylus-map.patch
a77e704065dfd015489a51647bbd4b6736cf1bbcadcd367c4c2325635398209e268b11dca97f6d9bb3051b987b9cb1d002caea0dcd77b919dfded3c86d90cb82  x11-perf.patch
"
